
"ui";

files.createWithDirs("/sdcard/xyuser.txt");
files.createWithDirs("/sdcard/pclog.txt");
files.createWithDirs("/sdcard/token.txt");
files.createWithDirs("/sdcard/sn.txt");
importClass(android.content.Context);

var 版本 = "V3.3.5"
var date, y, d, h, m, s, url, r, str, pclog, 限购份数, 分组, 延时, 检查分组次数, 用户数组, 用户, 售罄跳过
var groupId, projId, orderUnit, appKeys, appSecrets, projName
var 长度 = 99
var admin = "lxf@6789"
var 用户信息 = [{}]
var 用户数量 = 0
var dubug = 0


showUi()


function 登录验证() {
    switch (读取(5).substring(0, 2).toUpperCase()) {
        case "Q1":
            appKeys = "RPlXEJSIXT7Z6XOKpc"
            appSecrets = "P5zluBTa1UkLEZ6nKT69MviiqM4syALz"
            用户数量 = 二元(用户数量, 1)
            log("普通版-1机1号")
            qc()
            break
        case "Q2":
            appKeys = "xNebySLqm7tWs8obWQ"
            appSecrets = "WpJ5iGX3gW1MyngMGFfI6ZvmzruOHIFU"
            用户数量 = 二元(用户数量, 2)
            log("高级版-1机2号")
            qc()
            break
        case "Q3":
            appKeys = "okQE7pTkZpzwp0TR06"
            appSecrets = "932TDGriybg2XAyCYlQW1lPS3XZQXlxn"
            用户数量 = 二元(用户数量, 3)
            log("专业版-1机3号")
            qc()
            break
        default:
            toastLog("激活码不正确")
    }
}



function main() {
    for (let i = 0; i < 用户数量; i++) {
        用户信息.push({})
        用户信息[i].userMobile = 用户[i]
        用户信息[i].passwd = 用户数组[1]
        用户信息[i].alipayPassword = 用户数组[2]
        用户信息[i].设置份数 = 用户数组[3]
        用户信息[i].使用加速积分 = 用户数组[4]
        用户信息[i].激活码 = 用户数组[5]
        用户信息[i].抢单时间 = 用户数组[6]
        用户信息[i].积分转收益 = 用户数组[7]
        用户信息[i].自动提现 = 用户数组[8]
    }
    threads.start(function () {
        tim()
        setInterval(() => { times() }, 100);
    })
    threads.start(function () {
        xfc()
    })
    threads.start(function () {//唤醒设备
        device.keepScreenDim()
        while (true) {
            if (device.isScreenOn() != true) {
                device.wakeUp()
            }
            sleep(1000)
        }
    })
    if (Number(读取(6)) < 1000) {
        延时 = 1000
    } else {
        延时 = Number(读取(6))
    }

    while (true) {
        for (let i = 0; i < 用户数量; i++) {
            log("当前账户：" + 用户信息[i].userMobile)
            TOKEN(i)
            tea(i)
            检查仓券(i)
            积分收益(i)
            times()
            if (读取(8) != "false" && 用户信息[i].可提收益 >= 100 && h > 19 && h < 23) {
                自动提现(i)
                if (i == 用户数量 - 1) {
                    log("\n提现完毕\n\n")
                    return
                }
            }
            sleep(500)
        }
        log("等待开仓")
        while (true) {
            times()
            if (h == 9 || h > 9 || h == 15) {
                break
            }
            sleep(1000)
        }
        log("检查分组")
        for (let i = 0; i < 用户数量; i++) {
            TOKEN(i)
            用户信息[i].projName = []
            用户信息[i].抢单状态 = 0
            用户信息[i].关仓状态 = 0
        }
        检查分组()
        if (检查分组次数 > 4) {
            log("\n当前未开仓，抢单结束挂机中\n\n")
            sleep(3600000)
            continue
        }
        log("开抢了")
        /*****************检测加速积分******************* 
       for (let i = 0; i < 6; i++) {
           for (let i = 0; i < 用户数量; i++) {
               if (用户信息[0].使用加速积分 == "true") {
                   if (用户信息[i].抢单状态 == 1 || 用户信息[i].关仓状态 > 1 || 用户信息[i].可用份数 == 0 || 用户信息[i].加速积分份数 == 0) {
                       continue
                   }
                   检查仓位(i)
                   if (用户信息[i].可用份数 > 0 && 用户信息[i].加速积分份数 > 0 && projId != 0) {
                       开始下单(i)
                            if (售罄跳过 == 1) {
                       i--
                       continue
                   }
                       检查仓券(i)
                   }
               }
               sleep(延时)
           }
       }
       var 抢单结束 = 0
       for (let i = 0; i < 用户数量; i++) {
           if (用户信息[i].可用份数 > 0 && 用户信息[i].抢单状态 == 0) {
               抢单结束 = 1
               break
           }
       }
       if (抢单结束 == 0) {
           log("\n抢单结束,挂机中\n\n")
           sleep(3600000)
       }
       while (true) {
           times()
           if (m > 2) {
               break
           }
           sleep(1000)
       }  
       *********************************/
        for (let i = 0; i < 6; i++) {
            for (let i = 0; i < 用户数量; i++) {
                if (用户信息[i].抢单状态 == 1 || 用户信息[i].关仓状态 > 1 || 用户信息[i].可用份数 == 0) {
                    continue
                }
                检查仓位(i)
                if (用户信息[i].可用份数 > 0 && projId != 0) {
                    开始下单(i)
                    /*    if (售罄跳过 == 1) {
                           i--
                           continue
                       } */
                    检查仓券(i)
                }
                sleep(延时)
            }
        }
        log("\n抢单结束,挂机中\n\n")
        sleep(3600000)
    }
}



function tea(num) {
    log("开始种茶")
    for (let i = 1; i < 5; i++) {
        log(i + "号茶园")
        url = "https://v2live.wyliansuo.com/api/userms/oneAcreTeaGarden/getMemberTeaTreeByGardenType"
        r = http.postJson(url, {
            "token": 用户信息[num].token,
            "teaGardenType": i
        });
        if (r.statusCode == 200) {
            str = JSON.parse(r.body.string())
        }
        if (str.code == 1) {
            //检测本茶园有几棵树
            teaWater = str.data.length
            if (teaWater > 0) {
                for (let i = 0; i < teaWater; i++) {
                    //浇水
                    /*                    log(str.data[i].treeId) */
                    url = "https://v2live.wyliansuo.com/api/userms/oneAcreTeaGarden/waterDown"
                    r = http.postJson(url, {
                        "token": 用户信息[num].token,
                        "treeId": str.data[i].treeId
                    });
                    log("第" + (i + 1) + "棵树浇水：" + JSON.parse(r.body.string()).desc)
                    log("共浇水" + str.data[i].waterDownCount + "次")
                    /*          if (r.statusCode == 200) {
                                 str = JSON.parse(r.body.string())
                                 log(str.desc)
                             } */
                    //施肥
                    url = "https://v2live.wyliansuo.com/api/userms/oneAcreTeaGarden/spreadManure"
                    r = http.postJson(url, {
                        "token": 用户信息[num].token,
                        "treeId": str.data[i].treeId
                    });
                    log("第" + (i + 1) + "棵树施肥：" + JSON.parse(r.body.string()).desc)
                    log("共施肥" + str.data[i].spreadManureCount + "次")
                    /*        if (r.statusCode == 200) {
                                str = JSON.parse(r.body.string())
                                log(str.desc)
                              } */

                    //收茶

                    sleep(1000)
                }
            }
        }
        sleep(1000)
    }
    //加工
    url = "https://v2live.wyliansuo.com/api/userms//userWalletLog/getBalance"
    r = http.postJson(url, {
        "token": 用户信息[num].token,
        "commissionType": 53,
    });
    // log(JSON.parse(r.body.string()).desc)
    str = JSON.parse(r.body.string())
    log("可加工毛茶：" + str.data)


    url ="https://v2live.wyliansuo.com/api/userms/oneAcreTeaGarden/batchProcessMaocha"
    r = http.postJson(url, {
        "token": 用户信息[num].token,
    });
    str = JSON.parse(r.body.string())
    log("加工结果："+str.desc)



    // url = "https://v2live.wyliansuo.com/api/userms//userWalletLog/listByType"
    // r = http.postJson(url, {
    //     "token": 用户信息[num].token,
    //     "commissionType": 53,
    //     "freezingOfFund": 1,
    //     "page": 1,
    //     "size": 20
    // });
    // str = JSON.parse(r.body.string())
    // log("加工结果："+str.result[0].commissionValues)
    // log("加工结果："+str.desc)

}







function 检查分组() {
    检查分组次数 = 0
    url = "https://v2live.wyliansuo.com/api/orderms/CannibalizationBuy/queryTeaBarnGroupByH5"
    while (true) {
        检查分组次数++
        try {
            r = http.postJson(url, {
                "token": 用户信息[0].token,
                "page": 1,
                "size": 20
            });
        } catch (error) {
            sleep(延时)
            continue
        }

        if (r.statusCode == 200) {
            if (str.code != 1 && m < 1) {
                sleep(延时)
                TOKEN(0)
                logd(用户信息[0].token)
                sleep(延时)
                continue
            }

            if (检查分组次数 > 5) {
                return
            }
            /* logd(r.body.json().data.list[0].groupName) */
            //    logd(r.body.json().data.list[0].openStatus)
            str = r.body.json().data.list
            if (str == undefined || str == null) {
                sleep(延时)
                continue
            }

            var fz
            if (parseInt(Date.now() / 86400000) % 2 == 0) {
                fz = 1
            } else {
                fz = 0
            }
            分组 = str[fz].groupName
            限购份数 = str[fz].limitUnit
            groupId = str[fz].groupId//开仓分组
            检查分组次数 = 0
            log("分组信息：" + 分组)
            log("限购份数：" + 限购份数)
            return

            /* for (let i = 0; i < 2; i++) {
                if (str[i].openStatus == 1) {
                    分组 = str[i].groupName
                    限购份数 = str[i].limitUnit
                    groupId = str[i].groupId//开仓分组
                    检查分组次数 = 0
                    log("分组信息：" + 分组)
                    log("限购份数：" + 限购份数)
                    return
                }
            } */
        }
        sleep(延时)
    }
}








function 检查仓位(num) {
    logd("检查仓位")
    url = "https://v2live.wyliansuo.com/api/orderms/CannibalizationBuy/queryTeaBarnPositionByH5"
    while (true) {

        try {
            r = http.postJson(url, {
                "token": 用户信息[num].token,
                "groupId": groupId,
            });
        } catch (error) {
            sleep(延时)
            continue
        }

        logd("检测开仓状态")
        if (r.statusCode == 200) {
            str = JSON.parse(r.body.string())
            for (let i = 0; i < 50; i++) {
                if (str.data == null || str.data.position == null || str.data.position == undefined) {
                    sleep(100)
                } else {
                    break
                }
            }
            /*  log("str----" + str)
                log("str.data----" + str)
                log("str.data.position----" + str) */
            if (str.data == null || str.data.position == null || str.data.position == undefined) {
                projId = 0
                用户信息[num].关仓状态++
                return
            }
            if (str.data.position == 'max') {
                用户信息[num].抢单状态 = 1
                return
            }
            for (let i = 0; i < 6; i++) {
                if (str.data.position[i].projId != undefined) {
                    projId = str.data.position[i].projId
                    projName = Number(str.data.position[i].projName.replace(/[^\d]/g, " "))
                    用户信息[num].关仓状态 = 0
                    return
                }
            }
        }
        sleep(延时)
    }
}

function 开始下单(num) {
    log("当前账户：" + 用户信息[num].userMobile)
    if (用户信息[num].projName.indexOf(projName) >= 0) {
        return
    }
    用户信息[num].projName.push(projName)
    orderUnit = 三元(用户信息[num].可用份数, 限购份数, 用户信息[num].设置份数)//下单份数
    url = "https://v2live.wyliansuo.com/api/payms/Payment/confirmPayment"
    logd(读取(2))
    logd(groupId)
    logd(orderUnit)
    logd(projId)
    logd(用户信息[num].token)
    while (true) {
        try {
            r = http.postJson(url, {
                "alipayPassword": 读取(2),
                "groupId": groupId,//组别
                "orderUnit": orderUnit,
                "projId": projId,
                "token": 用户信息[num].token,
            });
        } catch (error) {
            logd("重新发数据1")
            sleep(延时)
            continue
        }
        if (r.statusCode == 200) {
            str = JSON.parse(r.body.string())
            logd(str.code)
            log(str.desc)

            if (str.code == 500010) {
                orderUnit = Number(str.desc.replace(/[^\d]/g, ""))//超出可购买份数
                continue
            }

            if (str.code == 500007 || str.code == 500008) {//售罄或者买过
                /*         售罄跳过 = 1 */
                return
            }
            if (str.code == 403001) {//抢单失败重新下单
                continue
            }
            if (str.code == 1) {
                // 售罄跳过 = 0
                times()
                files.append("/sdcard/pclog.txt", 用户信息[num].userMobile + " ― " + orderUnit + "份 " + d + "号 " + h + ":" + m + ":" + s + "\n")
                return
            }
        }
    }
}

function 检查仓券(num) {
    logd("检查仓券")
    //获取仓券积分
    用户信息[num].仓券 = 0
    用户信息[num].消费积分 = 0
    用户信息[num].加速积分 = 0
    用户信息[num].贡献积分 = 0
    url = "https://v2live.wyliansuo.com/api/payms//Payment/pcGetBalance"
    while (true) {

        try {
            r = http.postJson(url, {
                "token": 用户信息[num].token
            });
        } catch (error) {
            sleep(延时)
            continue
        }
        if (r.statusCode = 200) {
            str = JSON.parse(r.body.string())
            if (str.code != 1) {
                return 0
            }
            str = str.data
            用户信息[num].仓券 = str.cj
            用户信息[num].仓券份数 = parseInt(用户信息[num].仓券 / 100)
            用户信息[num].消费积分 = str.xfjf
            用户信息[num].消费积分份数 = parseInt(用户信息[num].消费积分 / 4)
            用户信息[num].加速积分 = str.jsjf
            用户信息[num].加速积分份数 = parseInt(用户信息[num].加速积分 / 10)
            用户信息[num].贡献积分 = str.gxjf
            log("仓券：" + 用户信息[num].仓券)
            log("消费积分：" + 用户信息[num].消费积分)
            log("加速积分：" + 用户信息[num].加速积分)
            log("贡献积分：" + 用户信息[num].贡献积分)
            用户信息[num].可用份数 = 二元(用户信息[num].仓券份数, 用户信息[num].消费积分份数)
            return
        }
        sleep(延时)
    }
}

function TOKEN(num) {
    /*  log("获取TOKEN") */
    //获取TOKEN
    用户信息[num].token = 0
    url = "https://v2live.wyliansuo.com/api/userms/wuyou/loginPasswd";
    while (true) {
        try {
            r = http.postJson(url, {
                "userMobile": 用户信息[num].userMobile,
                "passwd": 读取(1),
                "customerCode": "",
                "platForm": 1,
                "version": 51//682定制版本号
            });
        } catch (error) {
            sleep(延时)
            continue
        }
        if (r.statusCode == 200) {
            str = JSON.parse(r.body.string())
            if (str.code != "1") {
                logd(str.desc)
                logd(str.code)
                logd(str.data)
                sleep(延时)
                continue
            }
            用户信息[num].token = str.data
            /*    logd("TOKEN" + 用户信息[num].token) */
            if (用户信息[num].token != 0) {
                return
            } else {
                logd(str.desc)
            }
        }
        sleep(延时)
    }
}


function 积分收益(num) {
    let 等待 = 1
    times()
    if (m > 10 && m < 59) {
        等待 = 5000
    }
    //推广积分
    url = "https://v2live.wyliansuo.com/api/userms//userWalletLog/getBalance"
    r = http.postJson(url, {
        "commissionType": 12,
        "token": 用户信息[num].token
    });

    if (r.statusCode != 200) {
        return 0
    }
    str = JSON.parse(r.body.string())
    /*     log("积分收益" + str.data) */
    if (str.code == 1) {
        用户信息[num].推广积分 = str.data
        log("推广积分：" + 用户信息[num].推广积分)
    }


    r = http.postJson(url, {//链商配额
        "commissionType": 15,
        "token": 用户信息[num].token
    });
    if (r.statusCode != 200) {
        return 0
    }
    str = JSON.parse(r.body.string())
    /*     log("积分收益" + str.data) */
    if (str.code == 1) {
        用户信息[num].链商配额 = str.data
        log("链商配额：" + 用户信息[num].链商配额)
    }

    r = http.postJson(url, {//绿色积分
        "commissionType": 16,
        "token": 用户信息[num].token
    });
    if (r.statusCode != 200) {
        return 0
    }
    str = JSON.parse(r.body.string())
    /*     log("积分收益" + str.data) */
    if (str.code == 1) {
        用户信息[num].绿色积分 = str.data
        log("绿色积分：" + 用户信息[num].绿色积分)
    }

    r = http.postJson(url, {//链商指数
        "commissionType": 17,
        "token": 用户信息[num].token
    });
    if (r.statusCode != 200) {
        return 0
    }
    str = JSON.parse(r.body.string())
    /*     log("积分收益" + str.data) */
    if (str.code == 1) {
        用户信息[num].链商指数 = str.data
        log("链商指数：" + 用户信息[num].链商指数)
    }


    if (读取(7) != "false") {
        //积分转收益
        url = "https://v2live.wyliansuo.com/api/userms/commission/walletTransferAccounts"
        r = http.postJson(url, {
            "token": 用户信息[num].token,
            "commissionMoney": 用户信息[num].推广积分,
            "password": 读取(2),
            "transferOutCommissionType": "12",
            "transferInCommissionType": "13"
        });
        if (r.statusCode != 200) {
            return 0
        }
        str = JSON.parse(r.body.string())
        /*         log("积分转收益" + str.data) */
        /*  log(str.desc) */
    }

    //定农收益
    url = "https://v2live.wyliansuo.com/api/userms//userWalletLog/getBalance"

    r = http.postJson(url, {
        "commissionType": 8,
        "token": 用户信息[num].token
    });
    if (r.statusCode != 200) {
        return 0
    }
    str = JSON.parse(r.body.string())
    if (str.code == 1) {
        用户信息[num].代金券 = str.data
        log("代金券：" + 用户信息[num].代金券)
    }

    r = http.postJson(url, {
        "commissionType": 13,
        "token": 用户信息[num].token
    });
    if (r.statusCode != 200) {
        return 0
    }
    str = JSON.parse(r.body.string())
    /*     log("定农收益" + str.data) */
    if (str.code == 1) {
        用户信息[num].定农收益 = str.data
        log("定农收益：" + 用户信息[num].定农收益)
        用户信息[num].可提收益 = parseInt(用户信息[num].定农收益 / 100) * 100
    }
    sleep(等待)
}

function 保存() {
    files.write("/sdcard/xyuser.txt", ui.userName.getText() + "|" + ui.parssWord.getText() + "|" + ui.payParss.getText() + "|" + ui.cjxgInp.getText() + "|" + ui.jsjfOk.isChecked() + "|" + ui.userCard.getText() + "|" + ui.speed.getText() + "|" + ui.jfzsy.isChecked() + "|" + ui.zdtx.isChecked())
    files.write("/sdcard/sn.txt", ui.userCard.getText())
    // files.remove("/sdcard/user.txt")
    for (let i = 0; i < files.read("/sdcard/xyuser.txt").split("|").length; i++) {
        if (files.read("/sdcard/xyuser.txt").split("|")[i] == "") {
            toastLog("信息不完善")
            return 0
        }
    }
    if (files.read("/sdcard/xyuser.txt").split("|")[0].length > 29 && 读取(5) != admin) {
        toastLog("信息不正确，保存失败")
        return 0
    }
    用户数组 = files.read("/sdcard/xyuser.txt").split("|")
    用户 = 用户数组[0].split("-")
    for (let i = 0; i < 用户.length; i++) {
        if (用户[i] == "") {
            break
        }
        用户数量 = i + 1
    }
    return 1
}




function 自动提现(num) {
    //个人中心
    let 提现通道
    url = "https://v2live.wyliansuo.com/api/userms/sso/getuser"
    r = http.postJson(url, {
        "token": 用户信息[num].token
    });
    str = JSON.parse(r.body.string())
    str = str.data
    用户信息[num].userTel = str.userMobile//电话 
    用户信息[num].customerCode = str.customerCode//账号编码
    用户信息[num].userId = str.userId//用户ID

    //账户设置
    url = "https://v2live.wyliansuo.com/api/userms//realName/getRealNameAuthInfo"
    r = http.postJson(url, {
        "token": 用户信息[num].token,
        "customerCode": 用户信息[num].customerCode,
        "userAccount": 用户信息[num].customerCode
    });
    str = JSON.parse(r.body.string())
    str = str.data
    用户信息[num].userName = str.realName//实名

    //检查支付宝
    url = "https://v2live.wyliansuo.com/api/userms/aliPayBing/getInfoOne"
    r = http.postJson(url, {
        "userId": 用户信息[num].userId,
    });
    str = JSON.parse(r.body.string())
    str = str.data
    用户信息[num].alipayAccount = str//支付宝
    /*     log("支付宝--" + str) */

    //检查银行卡
    url = "https://v2live.wyliansuo.com/api/userms/customer/BankCard/queryBindCardList"
    r = http.postJson(url, {
        "token": 用户信息[num].token,
    });
    str = JSON.parse(r.body.string())
    str = str.data
    if (str[0] == undefined) {
        用户信息[num].accountNumber = undefined
    } else {
        用户信息[num].accountNumber = str[0].bankCardNumber
        /*        log("银行卡--" + 用户信息[num].accountNumber) */
    }

    if (用户信息[num].accountNumber == undefined && 用户信息[num].alipayAccount == undefined) {
        log("提现失败，请检查账户")
        return
    } else if (用户信息[num].accountNumber == undefined) {
        提现通道 = 用户信息[num].alipayAccount
    } else {
        提现通道 = 用户信息[num].bankCardNumber
    }

    //提现到银行卡
    url = "https://v2live.wyliansuo.com/api/userms/commission/walletCashWithdrawal";
    r = http.postJson(url, {
        "token": 用户信息[num].token,
        "commisonMoney": 用户信息[num].可提收益,
        "accountNumber": 提现通道,
        "userName": 用户信息[num].userName,
        "remark": "",
        "customerCode": 用户信息[num].customerCode,
        "userId": 用户信息[num].userId,
        "alipayPassword": 读取(2),
        "userMobile": 用户信息[num].userTel,
        "commissionType": 13,
        "cardType": 1,
        "platForm": 0,
    });
    if (r.statusCode == 200) {
        str = JSON.parse(r.body.string())
        log(str.desc)
    }
}





function 二元(a, b) {
    return a > b ? b : a
}

function 三元(a, b, c) {
    return (二元(a, b) > c ? c : 二元(a, b))
}

function times() {
    date = new Date();

    d = date.getDate()
    h = date.getHours()
    m = date.getMinutes()
    s = date.getSeconds()
}

function 读取(num) {
    let read = files.read("/sdcard/xyuser.txt").split("|")
    账号 = read[0]
    密码 = read[1]
    支付密码 = read[2]
    仓券限购份数 = read[3]
    使用加速积分 = read[4]
    激活码 = read[5]
    抢单间隔 = read[6]
    定农转收益 = read[7]
    收益自动提现 = read[8]
    return read[num]
}


function pl() {
    const CloudSDK = (function () {
        function CloudSDK(AppCode, TranPwd) {
            http.__okhttp__.setMaxRetries(0);
            http.__okhttp__.setTimeout(10 * 1000);
            this.event = events.emitter();
            //初始化类
            this._protocol = "http";
            this._host = "v1.27yz.net";
            this._host_jvm = "j1.27yz.net";
            this._Machine = this.getDeviceID();
            this._AppCode = AppCode;
            this._TranPwd = TranPwd;

            this._card = null;
            this._username = null;
            this._password = null;

            //数据处理类
            this._status = 0;
            this._error_message = "";
            this._ExpirationTime = "";
            this._StaticData = "";
            this._token = "";
            this._ucd = "";
            this._CurrentAccount = "";
            this._LoginType = 0;   //1.Reg 2.UserLogin 3.Trial

            this._auto_heartbeat = true;  // 是否自动开启心跳任务
            this._heartbeat_gap = 300 * 1000; // 默认300秒
            this._heartbeat_task = null;
            this._heartbeat_ret = 0;
        }
        CloudSDK.prototype.SetCard = function (card) {
            this._card = card.trim();
        }
        CloudSDK.prototype.SetUser = function (username, password) {
            this._username = username.trim();
            this._password = password;
        }
        CloudSDK.prototype.SetServer = function (id) {  //登录之前 设置服务器线路
            if (id == 0 || id == 1) {
                this._host = "v1.27yz.net";
                this._host_jvm = "j1.27yz.net";
            }
            if (id == 2) {
                this._host = "v2.27yz.net";
                this._host_jvm = "j2.27yz.net";
            }
            if (id == 3) {
                this._host = "v3.27yz.net";
                this._host_jvm = "j3.27yz.net";
            }
            if (id == 4) {
                this._host = "v4.27yz.cc";
                this._host_jvm = "j4.27yz.cc";
            }
        }
        CloudSDK.prototype.MD5 = function (str) {
            try {
                let digest = java.security.MessageDigest.getInstance("md5");
                let result = digest.digest(new java.lang.String(str).getBytes("UTF-8"));
                let buffer = new java.lang.StringBuffer();
                for (let index = 0; index < result.length; index++) {
                    let b = result[index];
                    let number = b & 0xff;
                    let str = java.lang.Integer.toHexString(number);
                    if (str.length == 1) {
                        buffer.append("0");
                    }
                    buffer.append(str);
                }
                return buffer.toString();
            } catch (error) {
                alert(error);
                return "";
            }
        }
        CloudSDK.prototype.getDeviceID = function () {
            let id = device.serial;
            if (id == null || id == "" || id == "unknown") {
                id = device.getAndroidId();
            }
            if (id == null || id == "" || id == "unknown") {
                id = device.getIMEI();
            }
            return this.MD5(id);
        }
        CloudSDK.prototype.genNonce = function () {
            return Math.round(Math.random() * 999999 + 100000);
        }
        CloudSDK.prototype.RespData = function (resp) {
            let ps = resp.split("|");
            if (ps.length == 2) {
                return { "code": ps[0], "message": ps[1] };
            } else {
                return { "code": 2, "message": "网络链接失败" };
            }
        }
        CloudSDK.prototype.RespSign = function (resp, cd, LoginType, CurrentAccount) {
            let ps = resp.split("|");
            this._LoginType = LoginType;
            if (ps.length == 2) {
                if (ps[0] == 2) {
                    this._status = 0;
                    this._error_message = ps[1];
                } else {
                    this._status = 0;
                }
            } else if (ps.length == 4) {
                if (ps[0] == 1) {
                    this._status = 1;
                    this._error_message = "";
                    this._ExpirationTime = ps[1];
                    this._StaticData = ps[2];
                    this._token = ps[3];
                    this._ucd = cd;
                    this._CurrentAccount = CurrentAccount;
                } else {
                    this._status = 0;
                }
            } else {
                this._status = 0;
                this._error_message = "网络链接失败";
                this._ExpirationTime = "";
                this._StaticData = "";
                this._token = "";
                this._ucd = "";
                this._CurrentAccount = "";
                this._LoginType = 0;   //1.Reg 2.UserLogin 3.Trial
            }
            return this._status;
        }

        /* 通用 */
        CloudSDK.prototype.GetHeartbeatResult = function () {
            return this._heartbeat_ret;
        }

        CloudSDK.prototype.QTime = function () {  //登录成功后取到期时间
            return this._ExpirationTime;
        }
        CloudSDK.prototype.JData = function () {  //登录成功后取静态数据
            return this._StaticData;
        }
        CloudSDK.prototype.GetInfo = function (Types) {  // 取软件信息  类型 (1为取公告 2为取版本号 3为取更新地址 4为取更新方式[返回0则为用户选择更新 1为系统强制更新])
            let Sign = this.MD5(this._AppCode + Types + this._TranPwd);
            let resp = http.post(this._protocol + "://" + this._host + "/HttpApi.ashx?action=GetInfo", { "AppCode": this._AppCode, "Types": Types, "Sign": Sign });
            return this.RespData(resp.body.string());
        }
        /* 卡密相关 */
        CloudSDK.prototype.Reg = function () {  // 卡密登录
            if (!this._card) {
                return { "code": 2, "message": "请先设置卡密" };
            }
            let cd = this.genNonce();
            let Sign = this.MD5(this._card + this._AppCode + this._Machine + cd + this._TranPwd);
            let resp = http.post(this._protocol + "://" + this._host + "/HttpApi.ashx?action=Reg", { "UserCode": this._card, "AppCode": this._AppCode, "Machine": this._Machine, "cd": cd, "Sign": Sign });
            if (this.RespSign(resp.body.string(), cd, 1, this._card) == 1) {
                if (this.MD5(Sign + cd + this._ExpirationTime + this._StaticData + this._TranPwd) == this._token) {
                    if (this._auto_heartbeat) {
                        this._startCheckStatus();
                    }
                    return { "code": 1, "message": "登录成功" };
                }
            }
            return { "code": 2, "message": this._error_message };
        }
        CloudSDK.prototype.Trial = function () {  // 试用登录
            let cd = this.genNonce();
            let Sign = this.MD5(this._AppCode + this._Machine + cd + this._TranPwd);
            let resp = http.post(this._protocol + "://" + this._host + "/HttpApi.ashx?action=Trial", { "AppCode": this._AppCode, "Machine": this._Machine, "cd": cd, "Sign": Sign });
            if (this.RespSign(resp.body.string(), cd, 3, "") == 1) {
                if (this.MD5(Sign + cd + this._ExpirationTime + this._StaticData + this._TranPwd) == this._token) {
                    if (this._auto_heartbeat) {
                        this._startCheckStatus();
                    }
                    return { "code": 1, "message": "登录成功" };
                }
            }
            return { "code": 2, "message": this._error_message };
        }
        CloudSDK.prototype.CheckStatus = function () {  // 心跳，默认会自动调用
            if (this._status == 0) {
                return 0;
            }
            let cd = this.genNonce();
            let Sign = this.MD5(this._CurrentAccount + this._LoginType + this._AppCode + this._Machine + this._ucd + cd + this._TranPwd);
            let resp = http.post(this._protocol + "://" + this._host + "/HttpApi.ashx?action=CheckStatus", { "User": this._CurrentAccount, "Types": this._LoginType, "ucd": this._ucd, "AppCode": this._AppCode, "Machine": this._Machine, "cd": cd, "Sign": Sign });
            let ps = resp.body.string().split("|");
            if (ps.length == 3) {
                if (ps[0] == 1) {
                    if (this.MD5(Sign + cd + ps[1] + this._TranPwd) == ps[2]) {
                        return ps[1];
                    }
                }
            }
            return 0;
        }
        CloudSDK.prototype._startCheckStatus = function () {  // 开启心跳任务
            if (this._heartbeat_task) {
                this._heartbeat_task.interrupt();
                this._heartbeat_task = null;
            }
            this._heartbeat_task = threads.start(function () {
                setInterval(function () { }, 10000);
            });
            this._heartbeat_ret = this.CheckStatus();
            this._heartbeat_task.setInterval((self) => {
                self._heartbeat_ret = self.CheckStatus();
                log("心跳返回值:" + self._heartbeat_ret);
                if (self._heartbeat_ret != 0) {
                    self.event.emit("heartbeat_failed", self._heartbeat_ret);
                }
            }, this._heartbeat_gap, this);
        }
        CloudSDK.prototype.ExitStatus = function () {  // 退出登录
            this._heartbeat_ret = { "code": 90, "message": "退出登录" };
            if (this._heartbeat_task) { // 结束心跳任务
                this._heartbeat_task.interrupt();
                this._heartbeat_task = null;
            }
            if (this._status == 0) {
                return { "code": 1, "message": "退出成功" };
            }
            let cd = this.genNonce();
            let Sign = this.MD5(this._CurrentAccount + this._LoginType + this._AppCode + this._Machine + this._ucd + cd + this._TranPwd);
            let resp = http.post(this._protocol + "://" + this._host + "/HttpApi.ashx?action=ExitStatus", { "User": this._CurrentAccount, "Types": this._LoginType, "ucd": this._ucd, "AppCode": this._AppCode, "Machine": this._Machine, "cd": cd, "Sign": Sign });
            let ret = this.RespData(resp.body.string());
            if (ret.code == 1) {
                this._status = 0;
                this._error_message = "";
                this._ExpirationTime = "";
                this._StaticData = "";
                this._token = "";
                this._ucd = "";
                this._CurrentAccount = "";
                this._LoginType = 0;
            }
            return ret;
        }
        CloudSDK.prototype.Unbind = function () {  // 单码模式下使用的解绑函数
            if (!this._card) {
                return { "code": 2, "message": "请先设置卡密" };
            }
            let Sign = this.MD5(this._card + this._AppCode + this._Machine + this._TranPwd);
            let resp = http.post(this._protocol + "://" + this._host + "/HttpApi.ashx?action=Unbind", { "UserCode": this._card, "AppCode": this._AppCode, "Machine": this._Machine, "Sign": Sign });
            return this.RespData(resp.body.string());
        }
        CloudSDK.prototype.Discount = function (Num) {  // 卡密扣点
            if (!this._card) {
                return { "code": 2, "message": "请先设置卡密" };
            }
            let cd = this.genNonce();
            let Sign = this.MD5(this._card + Num + this._AppCode + cd + this._TranPwd);
            let resp = http.post(this._protocol + "://" + this._host + "/HttpApi.ashx?action=Discount", { "UserCode": this._card, "AppCode": this._AppCode, "Num": Num, "cd": cd, "Sign": Sign });
            let ret = this.RespData(resp.body.string());
            if (ret.code == 1) {
                if (this.MD5(Sign + cd + this._TranPwd) == ret.message) {
                    return { "code": 1, "message": "扣点成功" };
                }
            }
            return ret;
        }
        CloudSDK.prototype.GetData = function (Types) {  // 单码模式的查询函数
            if (!this._card) {
                return { "code": 2, "message": "请先设置卡密" };
            }
            let Sign = this.MD5(this._card + Types + this._AppCode + this._TranPwd);
            let resp = http.post(this._protocol + "://" + this._host + "/HttpApi.ashx?action=GetData", { "UserCode": this._card, "AppCode": this._AppCode, "Types": Types, "Sign": Sign });
            return this.RespData(resp.body.string());
        }
        CloudSDK.prototype.SetData = function (Types, Datas) {  // 单码模式的设置数据函数
            if (!this._card) {
                return { "code": 2, "message": "请先设置卡密" };
            }
            let Sign = this.MD5(this._card + Types + Datas + this._AppCode + this._TranPwd);
            let resp = http.post(this._protocol + "://" + this._host + "/HttpApi.ashx?action=SetData", { "UserCode": this._card, "AppCode": this._AppCode, "Types": Types, "Datas": Datas, "Sign": Sign });
            return this.RespData(resp.body.string());
        }
        CloudSDK.prototype.CodeRecharge = function (UserCode, CardPwd) { // 以卡充卡 单码模式的充值函数
            let Sign = this.MD5(UserCode + CardPwd + this._AppCode + this._TranPwd);
            let resp = http.post(this._protocol + "://" + this._host + "/HttpApi.ashx?action=CodeRecharge", { "UserCode": UserCode, "AppCode": this._AppCode, "CardPwd": CardPwd, "Sign": Sign });
            return this.RespData(resp.body.string());
        }
        CloudSDK.prototype.JvmCall = function (FunId, Parm, FunPwd) {  // 登录成功后调用动态函数。
            let cd = this.genNonce();
            let Sign = this.MD5(this._CurrentAccount + this._LoginType + FunId + Parm + this._Machine + this._ucd + cd + FunPwd);
            let resp = http.post(this._protocol + "://" + this._host_jvm + "/Jvm.ashx?action=JvmCall", { "User": this._CurrentAccount, "Types": this._LoginType, "FunId": FunId, "Parm": Parm, "ucd": this._ucd, "Machine": this._Machine, "cd": cd, "Sign": Sign });
            return this.RespData(resp.body.string());
        }

        /* 用户相关 */
        CloudSDK.prototype.UserLogin = function () {  // 用户账号登录
            if (!this._username || !this._password) {
                return { "code": 2, "message": "请先设置用户账号密码" };
            }
            let cd = this.genNonce();
            let Sign = this.MD5(this._username + this._password + this._AppCode + this._Machine + cd + this._TranPwd);
            let resp = http.post(this._protocol + "://" + this._host + "/HttpApi.ashx?action=UserLogin", { "UserName": this._username, "UserPwd": this._password, "AppCode": this._AppCode, "Machine": this._Machine, "cd": cd, "Sign": Sign });
            if (this.RespSign(resp.body.string(), cd, 2, this._username) == 1) {
                if (this.MD5(Sign + cd + this._ExpirationTime + this._StaticData + this._TranPwd) == this._token) {
                    if (this._auto_heartbeat) {
                        this._startCheckStatus();
                    }
                    return { "code": 1, "message": "登录成功" };
                }
            }
            return { "code": 2, "message": this._error_message };
        }
        CloudSDK.prototype.UserUnbind = function () {  // 用户模式的解绑函数
            if (!this._username || !this._password) {
                return { "code": 2, "message": "请先设置用户账号密码" };
            }
            let Sign = this.MD5(this._username + this._password + this._AppCode + this._Machine + this._TranPwd);
            let resp = http.post(this._protocol + "://" + this._host + "/HttpApi.ashx?action=UserUnbind", { "UserName": this._username, "UserPwd": this._password, "AppCode": this._AppCode, "Machine": this._Machine, "Sign": Sign });
            return this.RespData(resp.body.string());
        }
        CloudSDK.prototype.UserDiscount = function (Num) {  // 用户模式扣点
            if (!this._username || !this._password) {
                return { "code": 2, "message": "请先设置用户账号密码" };
            }
            let cd = this.genNonce();
            let Sign = this.MD5(this._username + this._password + Num + this._AppCode + cd + this._TranPwd);
            let resp = http.post(this._protocol + "://" + this._host + "/HttpApi.ashx?action=UserDiscount", { "UserName": this._username, "UserPwd": this._password, "AppCode": this._AppCode, "Num": Num, "cd": cd, "Sign": Sign });
            let ret = this.RespData(resp.body.string());
            if (ret.code == 1) {
                if (this.MD5(Sign + cd + this._TranPwd) == ret.message) {
                    return { "code": 1, "message": "扣点成功" };
                }
            }
            return ret;
        }
        CloudSDK.prototype.UserGetData = function (Types) {  // 用户模式的查询函数
            if (!this._username || !this._password) {
                return { "code": 2, "message": "请先设置用户账号密码" };
            }
            let Sign = this.MD5(this._username + this._password + Types + this._AppCode + this._TranPwd);
            let resp = http.post(this._protocol + "://" + this._host + "/HttpApi.ashx?action=UserGetData", { "UserName": this._username, "UserPwd": this._password, "AppCode": this._AppCode, "Types": Types, "Sign": Sign });
            return this.RespData(resp.body.string());
        }
        CloudSDK.prototype.UserSetData = function (Types, Datas) {  // 用户模式的设置数据函数
            if (!this._username || !this._password) {
                return { "code": 2, "message": "请先设置用户账号密码" };
            }
            let Sign = this.MD5(this._username + this._password + Types + Datas + this._AppCode + this._TranPwd);
            let resp = http.post(this._protocol + "://" + this._host + "/HttpApi.ashx?action=UserSetData", { "UserName": this._username, "UserPwd": this._password, "AppCode": this._AppCode, "Types": Types, "Datas": Datas, "Sign": Sign });
            return this.RespData(resp.body.string());
        }
        CloudSDK.prototype.UserRegin = function (UserName, UserPwd, CardPwd, Proxy, Contact) {  // 用户模式的注册账号函数  用户名 密码 充值卡 代理商 联系方式
            let Sign = this.MD5(UserName + UserPwd + CardPwd + Proxy + Contact + this._Machine + this._AppCode + this._TranPwd);
            let resp = http.post(this._protocol + "://" + this._host + "/HttpApi.ashx?action=UserRegin", { "UserName": UserName, "UserPwd": UserPwd, "CardPwd": CardPwd, "Proxy": Proxy, "Contact": Contact, "Machine": this._Machine, "AppCode": this._AppCode, "Sign": Sign });
            return this.RespData(resp.body.string());
        }
        CloudSDK.prototype.UserRecharge = function (UserName, CardPwd, Referee) {  // 用户模式的充值函数  用户名  充值卡  推荐人
            let Sign = this.MD5(UserName + CardPwd + Referee + this._AppCode + this._TranPwd);
            let resp = http.post(this._protocol + "://" + this._host + "/HttpApi.ashx?action=UserRecharge", { "UserName": UserName, "CardPwd": CardPwd, "AppCode": this._AppCode, "Referee": Referee, "Sign": Sign });
            return this.RespData(resp.body.string());
        }
        CloudSDK.prototype.UserUpdatePwd = function (UserName, UserPwd, NewPwd) {  // 用户模式的修改账号密码函数
            let Sign = this.MD5(UserName + UserPwd + NewPwd + this._AppCode + this._TranPwd);
            let resp = http.post(this._protocol + "://" + this._host + "/HttpApi.ashx?action=UserUpdatePwd", { "UserName": UserName, "UserPwd": UserPwd, "AppCode": this._AppCode, "NewPwd": NewPwd, "Sign": Sign });
            return this.RespData(resp.body.string());
        }
        return CloudSDK;
    })();
    //官网：http://www.27yz.com/
    //在线文档：http://help.27yz.com/
    // AppCode和TranPwd  软件编号和传输密码 在云网络验证系统后台获取
    let _CloudSDK = new CloudSDK(appKeys, appSecrets);
    _CloudSDK.SetCard(读取(5));
    // 监听心跳事件
    _CloudSDK.event.on("heartbeat_failed", function (hret) {
        log("心跳:" + hret);
        sleep(2000);
        if (hret == 1) {
            toastLog("Error,您的注册码或账号已经过期！");
            sleep(1000);
            exit();  // 退出脚本
        }
        if (hret == 2) {
            toastLog("Error,内部错误,或者非法使用！");
            sleep(1000);
            exit();  // 退出脚本
        }
        if (hret == 3) {
            toastLog("Error,注册码或账号在别处使用,被迫下线！");
            sleep(1000);
            exit();  // 退出脚本
        }
        if (hret == 5) {
            toastLog("Error,注册码或账号被锁定,被迫下线！");
            sleep(1000);
            exit();  // 退出脚本
        }
        if (hret == 6) {
            toastLog("Error,该软件已停止服务,被迫下线！");
            sleep(1000);
            exit();  // 退出脚本
        }
        if (hret == 7) {
            toastLog("Error,机器码或IP被封停,被迫下线！");
            sleep(1000);
            exit();  // 退出脚本
        }
    });

    // 当脚本正常或者异常退出时会触发exit事件
    events.on("exit", function () {
        _CloudSDK.ExitStatus(); // 调用退出登录
        log("结束运行");
    });
    //toast(_CloudSDK.Unbind().message);

    let login_ret = _CloudSDK.Reg();
    if (login_ret.code == 1) {
        toast(login_ret.message + ",到期时间:" + _CloudSDK.QTime());
        // 登录成功，后面写你的业务代码
        main()
    } else {
        // 登录失败提示
        toast(login_ret.message);

    }

    // 当脚本正常或者异常退出时会触发exit事件
    events.on("exit", function () {
        _CloudSDK.ExitStatus(); // 调用退出登录
        log("结束运行");
    });
}

function qc() {
    const QCYSDK = (function () {
        function QCYSDK(appKey, appSecret) {
            http.__okhttp__.setMaxRetries(0);
            http.__okhttp__.setTimeout(10 * 1000);
            this.event = events.emitter();

            this.debug = true;
            this._lib_version = "v1.10";
            this._protocol = "http";
            this._hosts = ["api1.7ccccccc.com", "www.7ccccccc.com", "api2.7ccccccc.com"]
            this._host = this._hosts[0]
            this._device_id = this.getDeviceID();
            this._switch_count = 0;

            this._retry_count = 9;
            this._appKey = appKey;
            this._appSecret = appSecret;
            this._card = null;

            this._username = null;
            this._password = null;
            this._token = null;

            this.is_trial = false;
            this.login_result = {
                "card_type": "",
                "expires": "",
                "expires_ts": 0,
                "config": "",
            };

            this._auto_heartbeat = true;  // 是否自动开启心跳任务
            this._heartbeat_gap = 600 * 1000; // 默认600秒
            this._heartbeat_task = null;
            this._heartbeat_ret = { "code": -9, "message": "还未开始验证" };
            this._prev_nonce = null;
        }
        QCYSDK.prototype.switchHost = function () { // 切换备用服务器
            this._switch_count++;
            this._host = this._hosts[this._switch_count % this._hosts.length];
        }
        QCYSDK.prototype.SetCard = function (card) {
            this._card = card.trim();
        }
        QCYSDK.prototype.SetUser = function (username, password) {
            this._username = username.trim();
            this._password = password;
        }
        QCYSDK.prototype.MD5 = function (str) {
            try {
                let digest = java.security.MessageDigest.getInstance("md5");
                let result = digest.digest(new java.lang.String(str).getBytes("UTF-8"));
                let buffer = new java.lang.StringBuffer();
                for (let index = 0; index < result.length; index++) {
                    let b = result[index];
                    let number = b & 0xff;
                    let str = java.lang.Integer.toHexString(number);
                    if (str.length == 1) {
                        buffer.append("0");
                    }
                    buffer.append(str);
                }
                return buffer.toString();
            } catch (error) {
                alert(error);
                return "";
            }
        }
        /* 通用 */
        QCYSDK.prototype.GetHeartbeatResult = function () {
            return this._heartbeat_ret;
        }
        QCYSDK.prototype.GetTimeRemaining = function () {
            let g = this.login_result.expires_ts - this.getTimestamp();
            if (g < 0) {
                return 0;
            }
            return g;
        }
        QCYSDK.prototype.getDeviceID = function () {
            let id = device.serial;
            if (id == null || id == "" || id == "unknown") {
                id = device.getAndroidId();
            }
            if (id == null || id == "" || id == "unknown") {
                id = device.getIMEI();
            }
            return id;
        }
        /* 卡密相关 *//*卡密登录功能*/
        QCYSDK.prototype.CardLogin = function () {  // 卡密登录
            if (!this._card) {
                return { "code": -4, "message": "请先设置卡密" };
            }
            let method = "POST";
            let path = "/v1/card/login";
            let data = { "card": this._card, "device_id": this._device_id };
            let ret = this.Request(method, path, data);
            if (ret.code == 0) {
                this._token = ret.result.token;
                this.login_result = ret.result;
                if (this._auto_heartbeat) {
                    //调用心跳
                    this._startCardHeartheat();
                }
            }
            return ret;
        }
        /*卡密心跳*/
        QCYSDK.prototype.CardHeartbeat = function () {  // 卡密心跳，默认会自动调用
            if (!this._token) {
                return { "code": -2, "message": "请在卡密登录成功后调用" };
            }
            let method = "POST";
            let path = "/v1/card/heartbeat";
            let data = { "card": this._card, "token": this._token };
            let ret = this.Request(method, path, data);
            if (ret.code == 0) {
                this.login_result.expires = ret.result.expires;
                this.login_result.expires_ts = ret.result.expires_ts;
            }
            return ret;
        }
        QCYSDK.prototype._startCardHeartheat = function () {  // 开启卡密心跳任务
            if (this._heartbeat_task) {
                this._heartbeat_task.interrupt();
                this._heartbeat_task = null;
            }
            this._heartbeat_task = threads.start(function () {
                setInterval(function () { }, 10000);
            });
            this._heartbeat_ret = this.CardHeartbeat();
            this._heartbeat_task.setInterval((self) => {
                self._heartbeat_ret = self.CardHeartbeat();
                if (self._heartbeat_ret.code != 0) {
                    self.event.emit("heartbeat_failed", self._heartbeat_ret);
                }
            }, this._heartbeat_gap, this);
            this._heartbeat_task.setInterval((self) => {
                if (self.GetTimeRemaining() == 0) {
                    self.event.emit("heartbeat_failed", { "code": 10210, "message": "卡密已过期！" });
                }
            }, 1000, this);
        }
        QCYSDK.prototype.CardRecharge = function (card, useCard) { // 以卡充卡
            let method = "POST";
            let path = "/v1/card/recharge";
            let data = { "card": card, "useCard": useCard };
            return this.Request(method, path, data);
        }
        QCYSDK.prototype.CardLogout = function (token) {  // 卡密退出登录
            this._heartbeat_ret = { "code": -9, "message": "还未开始验证" };
            if (this._heartbeat_task) { // 结束心跳任务
                this._heartbeat_task.interrupt();
                this._heartbeat_task = null;
            }
            if (!token) {
                return { "code": 0, "message": "OK" };
            }
            let method = "POST";
            let path = "/v1/card/logout";
            let data = { "card": this._card, "token": token };
            let ret = this.Request(method, path, data);
            // 清理
            this._token = null;
            this.login_result = {
                "card_type": "",
                "expires": "",
                "expires_ts": 0,
                "config": "",
            };
            return ret;
        }
        QCYSDK.prototype.CardUnbindDevice = function () { // 卡密解绑设备，需开发者后台配置
            let method = "POST";
            let path = "/v1/card/unbind_device";
            let data = { "card": this._card, "device_id": this._device_id };
            return this.Request(method, path, data);
        }
        QCYSDK.prototype.SetCardUnbindPassword = function (password) { // 自定义设置解绑密码
            if (!this._token) {
                return { "code": -2, "message": "请在卡密登录成功后调用" };
            }
            let method = "POST";
            let path = "/v1/card/unbind_password";
            let data = { "card": this._card, "password": password, "token": this._token };
            return this.Request(method, path, data);
        }
        QCYSDK.prototype.CardUnbindDeviceByPassword = function (password) { // 用户通过解绑密码解绑设备
            let method = "POST";
            let path = "/v1/card/unbind_device/by_password";
            let data = { "card": this._card, "password": password };
            return this.Request(method, path, data);
        }
        /* 用户相关 */
        QCYSDK.prototype.UserRegister = function (username, password, card) {  // 用户注册（通过卡密）
            let method = "POST";
            let path = "/v1/user/register";
            let data = { "username": username, "password": password, "card": card, "device_id": this._device_id };
            return this.Request(method, path, data);
        }
        QCYSDK.prototype.UserLogin = function () {  // 用户账号登录
            if (!this._username || !this._password) {
                return { "code": -4, "message": "请先设置用户账号密码" };
            }
            let method = "POST";
            let path = "/v1/user/login";
            let data = { "username": this._username, "password": this._password, "device_id": this._device_id };
            let ret = this.Request(method, path, data);
            if (ret.code == 0) {
                this._token = ret.result.token;
                this.login_result = ret.result;
                if (this._auto_heartbeat) {
                    this._startUserHeartheat();
                }
            }
            return ret;
        }
        QCYSDK.prototype.UserHeartbeat = function () {  // 用户心跳，默认会自动开启
            if (!this._token) {
                return { "code": -2, "message": "请在用户登录成功后调用" };
            }
            let method = "POST";
            let path = "/v1/user/heartbeat";
            let data = { "username": this._username, "token": this._token };
            let ret = this.Request(method, path, data);
            if (ret.code == 0) {
                this.login_result.expires = ret.result.expires;
                this.login_result.expires_ts = ret.result.expires_ts;
            }
            return ret;
        }
        QCYSDK.prototype._startUserHeartheat = function () {  // 开启用户心跳任务
            if (this._heartbeat_task) {
                this._heartbeat_task.interrupt();
                this._heartbeat_task = null;
            }
            this._heartbeat_task = threads.start(function () {
                setInterval(function () { }, 10000);
            });
            this._heartbeat_ret = this.UserHeartbeat();

            this._heartbeat_task.setInterval((self) => {
                self._heartbeat_ret = self.UserHeartbeat();
                if (self._heartbeat_ret.code != 0) {
                    self.event.emit("heartbeat_failed", self._heartbeat_ret);
                }
            }, this._heartbeat_gap, this);

            this._heartbeat_task.setInterval((self) => {
                if (self.GetTimeRemaining() == 0) {
                    self.event.emit("heartbeat_failed", { "code": 10250, "message": "用户已到期！" });
                }
            }, 1000, this);
        }
        QCYSDK.prototype.UserLogout = function (token) {  // 用户退出登录
            this._heartbeat_ret = { "code": -9, "message": "还未开始验证" };
            if (this._heartbeat_task) { // 结束心跳任务
                this._heartbeat_task.interrupt();
                this._heartbeat_task = null;
            }
            if (!token) {
                return { "code": 0, "message": "OK" };
            }
            let method = "POST";
            let path = "/v1/user/logout";
            let data = { "username": this._username, "token": token };
            let ret = this.Request(method, path, data);
            // 清理
            this._token = null;
            this.login_result = {
                "card_type": "",
                "expires": "",
                "expires_ts": 0,
                "config": "",
            };
            return ret;
        }
        QCYSDK.prototype.UserChangePassword = function (username, password, newPassword) {  // 用户修改密码
            let method = "POST";
            let path = "/v1/user/password";
            let data = { "username": username, "password": password, "newPassword": newPassword };
            return this.Request(method, path, data);
        }
        QCYSDK.prototype.UserRecharge = function (username, card) { // 用户通过卡密充值
            let method = "POST";
            let path = "/v1/user/recharge";
            let data = { "username": username, "card": card };
            return this.Request(method, path, data);
        }
        QCYSDK.prototype.UserUnbindDevice = function () { // 用户解绑设备，需开发者后台配置
            let method = "POST";
            let path = "/v1/user/unbind_device";
            let data = { "username": this._username };
            return this.Request(method, path, data);
        }
        /* 配置相关 */
        QCYSDK.prototype.GetCardConfig = function () { // 获取卡密配置
            let method = "POST";
            let path = "/v1/card/config";
            let data = { "card": this._card };
            return this.Request(method, path, data);
        }
        QCYSDK.prototype.UpdateCardConfig = function (config) { // 更新卡密配置
            let method = "POST";
            let path = "/v1/card/config";
            let data = { "card": this._card, "config": config };
            return this.Request(method, path, data);
        }
        QCYSDK.prototype.GetUserConfig = function () { // 获取用户配置
            let method = "POST";
            let path = "/v1/user/config";
            let data = { "username": this._username };
            return this.Request(method, path, data);
        }
        QCYSDK.prototype.UpdateUserConfig = function (config) { // 更新用户配置
            let method = "POST";
            let path = "/v1/user/config";
            let data = { "username": this._username, "config": config };
            return this.Request(method, path, data);
        }
        /* 软件相关 */
        QCYSDK.prototype.GetSoftwareConfig = function () { // 获取软件配置
            let method = "POST";
            let path = "/v1/software/config";
            return this.Request(method, path, {});
        }
        QCYSDK.prototype.GetSoftwareNotice = function () { // 获取软件通知
            let method = "POST";
            let path = "/v1/software/notice";
            return this.Request(method, path, {});
        }
        QCYSDK.prototype.GetSoftwareVersion = function () { // 获取软件版本
            let method = "POST";
            let path = "/v1/software/latest_ver";
            return this.Request(method, path, {});
        }
        /* 试用功能 */
        QCYSDK.prototype.TrialLogin = function () {  // 试用登录
            let method = "POST";
            let path = "/v1/trial/login";
            let data = { "device_id": this._device_id };
            let ret = this.Request(method, path, data);
            if (ret.code == 0) {
                this.is_trial = true;
                this.login_result = ret.result;
                this._token = ret.result.token;
                if (this._auto_heartbeat) {
                    this._startTrialHeartheat();
                }
            }
            return ret;
        }
        QCYSDK.prototype.TrialHeartbeat = function () {  // 试用心跳，默认会自动调用
            let method = "POST";
            let path = "/v1/trial/heartbeat";
            let data = { "device_id": this._device_id, "token": this._token };
            let ret = this.Request(method, path, data);
            if (ret.code == 0) {
                this.login_result.expires = ret.result.expires;
                this.login_result.expires_ts = ret.result.expires_ts;
            }
            return ret;
        }
        QCYSDK.prototype._startTrialHeartheat = function () {  // 开启试用心跳任务
            if (this._heartbeat_task) {
                this._heartbeat_task.interrupt();
                this._heartbeat_task = null;
            }
            this._heartbeat_task = threads.start(function () {
                setInterval(function () { }, 10000);
            });
            this._heartbeat_ret = this.TrialHeartbeat();
            this._heartbeat_task.setInterval((self) => {
                self._heartbeat_ret = self.TrialHeartbeat();
                if (self._heartbeat_ret.code != 0) {
                    self.event.emit("heartbeat_failed", self._heartbeat_ret);
                }
            }, this._heartbeat_gap, this);
            this._heartbeat_task.setInterval((self) => {
                if (self.GetTimeRemaining() == 0) {
                    self.event.emit("heartbeat_failed", { "code": 10407, "message": "试用已到期！" });
                }
            }, 1000, this);
        }
        QCYSDK.prototype.TrialLogout = function () {  // 试用退出登录，没有http请求，只是清理本地记录
            this.is_trial = false;
            this._heartbeat_ret = { "code": -9, "message": "还未开始验证" };
            if (this._heartbeat_task) { // 结束心跳任务
                this._heartbeat_task.interrupt();
                this._heartbeat_task = null;
            }
            // 清理
            this._token = null;
            this.login_result = {
                "card_type": "",
                "expires": "",
                "expires_ts": 0,
                "config": "",
            };
            return { "code": 0, "message": "OK" };
        }
        /* 高级功能 */
        QCYSDK.prototype.GetRemoteVar = function (key) { // 获取远程变量
            let method = "POST";
            let path = "/v1/af/remote_var";
            let data = { "varName": key, "token": this._token };
            return this.Request(method, path, data);
        }
        QCYSDK.prototype.GetRemoteData = function (key) { // 获取远程数据
            let method = "POST";
            let path = "/v1/af/remote_data";
            let data = { "key": key, "token": this._token };
            return this.Request(method, path, data);
        }
        QCYSDK.prototype.CreateRemoteData = function (key, value) { // 创建远程数据
            let method = "POST";
            let path = "/v1/af/remote_data";
            let data = { "action": "create", "key": key, "value": value, "token": this._token };
            return this.Request(method, path, data);
        }
        QCYSDK.prototype.UpdateRemoteData = function (key, value) { // 修改远程数据
            let method = "POST";
            let path = "/v1/af/remote_data";
            let data = { "action": "update", "key": key, "value": value, "token": this._token };
            return this.Request(method, path, data);
        }
        QCYSDK.prototype.DeleteRemoteData = function (key) { // 删除远程数据
            let method = "POST";
            let path = "/v1/af/remote_data";
            let data = { "action": "delete", "key": key, "token": this._token };
            return this.Request(method, path, data);
        }
        QCYSDK.prototype.CallRemoteFn = function (fnName, params) { // 云函数
            let method = "POST";
            let path = "/v1/af/call_remote_func";
            let data = { "fnName": fnName, "params": params, "token": this._token };
            return this.Request(method, path, data);
        }
        QCYSDK.prototype.Request = function (method, path, params) {
            // 构建公共参数
            params["appKey"] = this._appKey;
            method = method.toUpperCase();
            let max_retries = this._retry_count;
            let retries_count = 0;

            let data = { "code": -1, "message": "连接服务器失败" };
            do {
                retries_count++;
                let url = this._protocol + "://" + this._host + path
                let sec = this.retry_fib(retries_count);
                delete params["sign"]
                params["nonce"] = this.genNonce();
                params["timestamp"] = this.getTimestamp();
                let ps = this.joinParams(params);
                let s = method + this._host + path + ps + this._appSecret;
                let sign = this.MD5(s);
                params["sign"] = sign;
                let resp, body;
                try {
                    if (method === "GET") {
                        resp = http.get(url + "?" + ps + "&sign=" + sign);
                    } else {  // POST
                        resp = http.post(url, params);
                    }
                    body = resp.body.string();
                    data = JSON.parse(body);
                    this._debug(method + '-' + path + ':', params, data);
                    let crs = this.CheckRespSign(data);
                    if (crs.code !== 0) {
                        return crs;
                    } else {
                        return data;
                    }
                } catch (error) {
                    // log("[*] request error: ", error, sec + "s后重试");
                    this._debug(method + '-' + path + ':', params, body)
                    this.switchHost();
                    sleep(sec * 1000);
                }
            } while (retries_count < max_retries);
            return data;
        }
        /*工具类*/
        QCYSDK.prototype.retry_fib = function (num) {
            if (num > 9) {
                return 34
            }
            let a = 0;
            let b = 1;
            for (i = 0; i < num; i++) {
                let tmp = a + b;
                a = b
                b = tmp
            }
            return a
        }
        QCYSDK.prototype.genNonce = function () {
            const ascii_str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
            let tmp = '';
            for (let i = 0; i < 20; i++) {
                tmp += ascii_str.charAt(Math.round(Math.random() * ascii_str.length));
            }
            return this.MD5(this._device_id + this._prev_nonce + new Date().getTime() + tmp);
        }
        QCYSDK.prototype.getTimestamp = function () {
            try {
                let res = http.get("http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp");
                let data = res.data.json()
                return Math.floor(data["data"]["t"] / 1000);
            } catch (error) {
                return Math.floor(new Date().getTime() / 1000);
            }
        }
        QCYSDK.prototype.joinParams = function (params) {
            let ps = [];
            for (let k in params) {
                ps.push(k + "=" + params[k])
            }
            ps.sort()
            return ps.join("&")
        }
        QCYSDK.prototype.CheckRespSign = function (resp) {
            if (resp.code != 0 && resp.nonce === "" && resp.sign === "") {
                return resp
            }
            let ps = "";
            if (resp["result"]) {
                ps = this.joinParams(resp["result"]);
            }
            let s = resp["code"] + resp["message"] + ps + resp["nonce"] + this._appSecret;
            let sign = this.MD5(s);
            if (sign === resp["sign"]) {
                return { "code": 0, "message": "OK" };
            }
            return { "code": -99, "message": "CRS:签名校验失败" };
        }
        QCYSDK.prototype._debug = function (path, params, result) {
            if (this.debug) {
                console.log("\n" + path, "\nparams:", params, "\nresult:", result)
            }
        }
        return QCYSDK;
    })();


    /* 将QCYSDK.js文件中的代码复制粘贴到上面 */
    let qcysdk = new QCYSDK(appKeys, appSecrets);
    qcysdk.debug = false; // 开发时建议开启debug，有详细输出
    qcysdk.SetCard(读取(5));
    // 监听心跳失败事件
    qcysdk.event.on("heartbeat_failed", function (hret) {
        log("心跳失败，尝试重登...")
        sleep(2000);
        let login_ret = qcysdk.CardLogin();
        if (login_ret.code == 0) {
            log("重登成功");
        } else {
            toastLog(login_ret.message);  // 重登失败
            sleep(200);
            exit();  // 退出脚本
        }
    });

    // 当脚本正常或者异常退出时会触发exit事件
    events.on("exit", function () {
        qcysdk.CardLogout(); // 调用退出登录
        log("结束运行");
    });
    // 卡密登录
    // 登录成功后将自动启动一个线程发送心跳包，开发者只需监听心跳失败事件做处理就行了

    let login_ret = qcysdk.CardLogin();

    if (login_ret.code == 0) {
        // 登录成功，后面写你的业务代码
        toastLog('剩余有效期' + parseInt(qcysdk.GetTimeRemaining() / 86400 + 1) + "天")
        main()
    } else {
        toast(login_ret.message);  // 登录失败的提示信息
    }

}



function showUi() {
    if (读取(5) != admin) {
        长度 = 29
    }
    $ui.layout(
        <vertical bg="#ffffff" >
            <vertical h="20" bg='#009bfb' />
            <frame >
                <horizontal h="60" w='*' bg='#009bfb' >
                    <text text="🔥" color="#ffffff" textSize='40' w="auto" h="auto" marginLeft='5' />
                    <text text="开抢了" color="#ffffff" textSize='22' textStyle='bold' w="auto" h="auto" />
                    <text text="{{版本}}" color="#ffffff" textSize='12' textStyle='bold' w="auto" h="auto" />
                </horizontal>
                <Switch id="autoShow" text="悬浮窗权限:" textStyle='bold' textColor='#ffffff' textSize='12' checked="{{floaty.checkPermission() != false}}" w="auto" margin='0 30 5 0' layout_gravity="right|bottom" />
            </frame>
            <vertical padding='5 0 5 0' >
                <TextView id="tv_text" singleLine="true" textStyle='bold' ellipsize="marquee" focusable="true" textSize='12' text="温馨提醒：【单开版-1机1号/双开版-1机2号/多开版-1机3号】已上线，欢迎使用。" textColor="#ff4782" w='*' h='auto' /> //textColor="#ff4782"
                <horizontal marginTop='5'>
                    <text text="定农账号" color="#000000" textSize='12' textStyle='bold' gravity='center' />
                    <input id="userName" w='260' textSize='12' maxLength='{{长度}}' lines="1" gravity='center' hint="C字头账号,多号用减号“-”分隔,最多3个号" />
                </horizontal>
                <horizontal marginTop='5'>
                    <horizontal layout_weight='1' w='150'>
                        <text text="登录密码" color="#000000" textSize='12' textStyle='bold' gravity='center' />
                        <input id="parssWord" w='90' textSize='12' lines="1" maxLength='20' gravity='center' inputType="textPassword" hint='请输入密码' />
                    </horizontal>
                    <horizontal layout_weight='1' w='150'>
                        <text text="支付密码" color="#000000" textSize='12' textStyle='bold' gravity='center' />
                        <input id="payParss" w='90' textSize='12' lines="1" maxLength='6' inputType='numberPassword' gravity='center' hint='6位支付密码' />
                    </horizontal>
                </horizontal>
                <horizontal marginTop='5'>
                    <horizontal layout_weight='1' w='150'>
                        <text text="仓券限购" color="#000000" textSize='12' textStyle='bold' gravity='center' />
                        <input id="cjxgInp" w='70' textSize='12' lines="1" maxLength='2' inputType='number' gravity='center' hint='100仓券为1份' />
                        <text text="份" color="#000000" textSize='12' textStyle='bold' gravity='center' />
                    </horizontal>
                    <horizontal layout_weight='1' w='150'>
                        <text text="抢单间隔" color="#000000" textSize='12' textStyle='bold' gravity='center' />
                        <input id="speed" w='70' textSize='12' text='2000' lines="1" maxLength='4' inputType='number' gravity='center' hint='请适当微调' />
                        <text text="毫秒" color="#000000" textSize='12' textStyle='bold' gravity='center' />
                    </horizontal>
                </horizontal>
                <horizontal marginTop='5'>
                    <checkbox layout_weight='1' id='jsjfOk' checked='false' text="使用加速积分" textStyle='bold' color="#000000" textSize='12' />
                    <checkbox layout_weight='1' id='jfzsy' checked='false' text="积分自动转收益" textStyle='bold' color="#000000" textSize='12' />
                    <checkbox layout_weight='1' id='zdtx' checked='false' text="自动提现" textStyle='bold' color="#000000" textSize='12' />
                </horizontal>
                <horizontal marginTop='5'>
                    <text text="激活码/卡密" color="#000000" textSize='12' textStyle='bold' gravity='center' />
                    <input id="userCard" w='260' textSize='9' lines="1" gravity='center' hint='请输入激活码' inputType="textPassword" />
                </horizontal>
                <horizontal marginTop='5'>
                    <button layout_weight='1' id="readpclog" text="抢单记录" color="#ffffff" textSize='10' textStyle='bold' w='auto' h='35' style="Widget.AppCompat.Button.Colored" />
                    <button layout_weight='1' id="delpclog" text="清除记录" color="#ffffff" textSize='10' textStyle='bold' w='auto' h='35' style="Widget.AppCompat.Button.Colored" />
                    <button layout_weight='1' id="cls" text="解绑卡密" color="#ffffff" textSize='10' textStyle='bold' w='auto' h='35' style="Widget.AppCompat.Button.Colored" />
                    <button layout_weight='1' id="save" text="保存设置" color="#ffffff" textSize='10' textStyle='bold' w='auto' h='35' style="Widget.AppCompat.Button.Colored" />
                </horizontal>
                <vertical marginLeft='20'>
                    <text text="温馨提示：" color="#009bfb" textSize='12' textStyle='bold' marginTop='10' w='250' layout_gravity='left' />
                    <text text="●本软件可添加1~3个账户。" color="#009bfb" textSize='12' textStyle='bold' w='300' layout_gravity='left' />
                    <text text="●支持24小时无人值守，抢单无需人工干预。" color="#009bfb" textSize='12' textStyle='bold' w='300' layout_gravity='left' />
                    <text text="●多账户登录，登录密码与支付密码须保持一致。" color="#009bfb" textSize='12' textStyle='bold' w='300' layout_gravity='left' />
                    <text text="●账户之间用减号“-”分隔。" color="#009bfb" textSize='12' textStyle='bold' mw='300' layout_gravity='left' />
                    <text text="●请合理设置抢单间隔时间。" color="#ff0000" textSize='12' textStyle='bold' w='300' layout_gravity='left' />
                    <text text="●首次绑定激活码须先保存退出一次。" color="#009bfb" textSize='12' textStyle='bold' w='300' layout_gravity='left' />
                    <text text="●激活码1机1码，遗失不补，请妥善保管。" color="#009bfb" textSize='12' textStyle='bold' w='300' layout_gravity='left' />
                </vertical>
            </vertical>
            <frame w='*' h='*'>
                <horizontal gravity="bottom|center" marginBottom='30'>
                    <button id="start" text="启动" color="#ffffff" textSize='13' textStyle='bold' w="*" h="auto" style="Widget.AppCompat.Button.Colored" />
                </horizontal>
            </frame>
        </vertical>
    )

    //去除标题栏
    activity.window.addFlags(android.view.View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
    ui.statusBarColor("#000000");
    //走马灯
    ui.tv_text.setSelected(true);
    // 悬浮窗权限
    ui.autoShow.on("check", function (checked) {
        importClass(android.content.Intent);
        importClass(android.net.Uri);
        importClass(android.provider.Settings);
        var intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
            Uri.parse("package:" + context.getPackageName()));
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        app.startActivity(intent);
    });

    //解绑手机
    ui.cls.click(function () {
        let carUnb_let = threads.start(function () {
            carUnb_let = qcysdk.CardUnbindDevice()
            if (carUnb_let.code == 0) {
                toastLog("解绑成功")
                sleep(3000)
                carUnb_let.interrupt()
            }
        })
    });

    ui.save.click(function () {
        保存()
        toastLog("保存成功")
    })

    ui.readpclog.click(function () {
        threads.start(function () {
            logUi()
        })
    });

    ui.delpclog.click(function () {
        files.write("/sdcard/pclog.txt", "")
        toast("清除成功")
    });
    let ks = 0
    ui.start.click(function () {
        if (floaty.checkPermission() == false) {
            toast("请先开启悬浮窗权限！")
            return;
        }

        if (ks == 0 && 保存() == 1) {
            ks = 1
            var thread = threads.start(function () {
                if (读取(5) != admin) {
                    登录验证()
                } else {
                    main()
                }
            })
            if (ui.start.getText == "启动") {
                ui.start.setText("退出")
            } else {
                ui.start.setText("退出")
            }
            return
        }
        if (ks == 1) {
            device.cancelKeepingAwake()
            exit()
        }
    });

    if (files.read("/sdcard/xyuser.txt").split("|").length > 5) {
        ui.userName.setText(读取(0))
        ui.parssWord.setText(读取(1))
        ui.payParss.setText(读取(2))
        ui.cjxgInp.setText(读取(3))
        if (读取(4) == "true") {
            ui.jsjfOk.setChecked(true)
        } else {
            ui.jsjfOk.setChecked(false)
        }
        ui.userCard.setText(读取(5))
        if (读取(6) != undefined) {
            ui.speed.setText(读取(6))
        }
        if (读取(7) == "true") {
            ui.jfzsy.setChecked(true)
        } else {
            ui.jfzsy.setChecked(false)
        }
        if (读取(8) == "true") {
            ui.zdtx.setChecked(true)
        } else {
            ui.zdtx.setChecked(false)
        }
    }
}

function tim() {
    let win = floaty.rawWindow(
        <frame w="200" gravity="center" bg="#88000000">
            <text id="text" textColor="yellow" gravity="center">
            </text>
        </frame>
    );
    //w.setAdjustEnabled(true);
    win.setPosition(0, 90);
    win.setTouchable(false);
    setInterval(function () {
        ui.run(function () {
            date = new Date()
            win.text.setText(util.format("时间: %d:%d:%d:%d", date.getHours(), date.getMinutes(), date.getSeconds(), parseInt(date.getMilliseconds() / 100)));
        })
    }, 100); //
}

function xfc() {
    /*     read = files.read("/sdcard/user.txt").split("|") */
    /*  账号 = read[0]
     密码 = read[1] */
    颜色 = "#88000000"
    宽度 = 200
    高度 = 500
    let win = floaty.rawWindow(
        <vertical>
            <com.stardust.autojs.core.console.ConsoleView id="console" h="{{高度}}" w="{{宽度}}" bg="{{颜色}}" />
        </vertical>
    );
    //悬浮穿透
    win.setTouchable(false);
    //悬浮移动
    win.setPosition(0, 150);
    //时钟死循环
    setInterval(() => { }, 1000);
    //去除控制台按钮
    //win.console.setInputEnabled(true);
    //加载日志信息到ui控制台
    win.console.setConsole(runtime.console);
}

function logUi() {
    if (files.read("/sdcard/pclog.txt") == "") {
        toast("无抢单记录")
        return
    }
    pclog = files.read("/sdcard/pclog.txt")
    var logUi = floaty.window(
        <ScrollView>
            <vertical w='*' h='*'  >
                <text id="text" text="{{pclog}}" textSize="15" padding='10' textColor='#000000' bg='#f5f8fb' />
            </vertical>
        </ScrollView>
    );
    logUi.setPosition(50, 200)
    /*     logUi.exitOnClose(); */
    logUi.text.click(() => {
        logUi.close()
    });
    setInterval(() => { }, 1000);
}


function logd(obj) {
    if (dubug == 1) {
        log(obj)
    }
}